import { useUserStore } from '@/store/user'

// 检查 token 是否过期，这里简单假设通过时间戳判断
export const isTokenExpired = (tokenExpiration: number) => {
  const currentTime = Date.now()
  return currentTime > tokenExpiration
}

// 清除所有缓存
export const clearAllCache = () => {
  const userStore = useUserStore()
  userStore.clearToken()
  userStore.clearUserInfo()
  uni.clearStorageSync()
}

// 检查 token 并处理过期情况
export const checkTokenExpiration = () => {
  const userStore = useUserStore()
  const tokenExpiration = userStore.tokenExpiration
  if (tokenExpiration && isTokenExpired(tokenExpiration)) {
    clearAllCache()
  }
}
